'''
Created on 2011-1-26

@author: Q
'''
import os, thread, socket, string
port = 11120
hostname = "fs3.das4.tudelft.nl"



def RunTimeManager():
#    thread.start_new_thread(listenNewJobs, ())
    return True

def submitExps(expName, factors, numOfExperiments, servername="anyServer", ipAddress=hostname):
    for i in range(0, numOfExperiments):
        instances = 1;
        s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
        s.connect((ipAddress,port))
        s.settimeout(5)
        paras = " " + servername + " %d"%instances
        for factor in factors:
            paras = paras + " %d"%factor
        s.send(expName + paras)
        content = s.recv(1024)
        if string.strip(content) == "ok":
            print "submit " + expName, factors, instances, servername
        s.close()
        
if __name__ == "__main__":
    #submit job to DAS-4
#    submitExps("1a1", [1], 1, "anyServer", "127.0.0.1")
    #submit job to Cloud
    submitExps("1a1", [1], 10, "m1.small", "127.0.0.1")
    
#    submitExps("1a2", [1], 1, "anyServer", "127.0.0.1")